#include <net/net.h>
#include <g-bios.h>
#include <core/init.h>
#include <core/errno.h>


static int main(int argc, char *argv[])
{
	struct sockaddr *sockAddr;
	struct Socket stSocket;
	char szDestIp[IPV4_STR_LEN];
	UINT32 nip;


	if (1 == argc)
	{
		GuIpToStr(szDestIp, CONF_SVR_IP);
	}
	else
	{
		strncpy(szDestIp, argv[1], IPV4_STR_LEN - 1);
		szDestIp[IPV4_STR_LEN - 1] = '\0';
	}

	GuStrToIp((BYTE *)&nip, szDestIp);

	sockAddr = getaddr(nip);

	if (NULL == sockAddr)
	{
		sockAddr = gethostaddr(szDestIp);

		if (NULL == sockAddr)
		{
			printf("Fail to find host %s!\n", argv[1]);
			return -EIO;
		}
	}
	
#if 0
	printf("%s -> %02x:%02x:%02x:%02x:%02x:%02x. OK\n", 
		szDestIp,
		sockAddr->pbDesMac[0],
		sockAddr->pbDesMac[1],
		sockAddr->pbDesMac[2],
		sockAddr->pbDesMac[3],
		sockAddr->pbDesMac[4],
		sockAddr->pbDesMac[5]
		);
#else
	memcpy(&stSocket.addr, sockAddr, sizeof(struct sockaddr));

    PingReqest(&stSocket);
#endif

	return 0;
}


INSTALL_APPLICATION(ping, main, "need help? :)");

